//
//  LookMoreViewController.m
//  Beauty
//
//  Created by Snow on 16/9/17.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "LookMoreViewController.h"
#import "GXMacro.h"
#import "ModelOfMineWindow.h"
#import "MyWindowCollectionViewCell.h"
#import "HotWindowViewController.h"
@interface LookMoreViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@end

@implementation LookMoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createView];
}
- (void)createView
{
    _layout = [[UICollectionViewFlowLayout alloc] init];
    _layout.itemSize = CGSizeMake((SCREEN_WIDTH - 30) / 2, 230);
    _layout.minimumLineSpacing = 10;
    _layout.minimumInteritemSpacing = 10;
    _layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    _collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:_layout];
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    [self.view addSubview:_collectionView];
    [_collectionView registerClass:[MyWindowCollectionViewCell class] forCellWithReuseIdentifier:@"MyWindowCollectionViewCell1"];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _arrOfModel.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MyWindowCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWindowCollectionViewCell1" forIndexPath:indexPath];
    ModelOfMineWindow *model = [_arrOfModel objectAtIndex:indexPath.row];
    cell.labelOfWindowName.text = model.favorites_class_name;
    cell.labelOfMomentCount.text = [NSString stringWithFormat:@"共%@个瞬间", model.micro_personal_count];
    NSArray *arr = model.micro_personal;
    NSMutableArray *array = [NSMutableArray array];
    for (NSDictionary *dic in arr) {
        [array addObject:dic[@"commend_image"]];
    }
    if (array.count >= 1) {
        [cell.image1 sd_setImageWithURL:[NSURL URLWithString:array[0]]];
    }
    if (array.count >= 2) {
        [cell.image1 sd_setImageWithURL:[NSURL URLWithString:array[0]]];
        [cell.image2 sd_setImageWithURL:[NSURL URLWithString:array[1]]];
    }
    if (array.count >= 3) {
        [cell.image3 sd_setImageWithURL:[NSURL URLWithString:array[2]]];
        [cell.image1 sd_setImageWithURL:[NSURL URLWithString:array[0]]];
        [cell.image2 sd_setImageWithURL:[NSURL URLWithString:array[1]]];
        
    }
    if (array.count >= 4) {
        [cell.image3 sd_setImageWithURL:[NSURL URLWithString:array[2]]];
        [cell.image1 sd_setImageWithURL:[NSURL URLWithString:array[0]]];
        [cell.image2 sd_setImageWithURL:[NSURL URLWithString:array[1]]];
        [cell.image4 sd_setImageWithURL:[NSURL URLWithString:array[3]]];
    }
    
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ModelOfMineWindow *model = [_arrOfModel objectAtIndex:indexPath.row];
    HotWindowViewController *hot = [[HotWindowViewController alloc] init];
    self.tabBarController.tabBar.hidden = YES;
    hot.favorita_class_id = model.favorites_class_id;
    [self.navigationController pushViewController:hot animated:NO];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)setArrOfModel:(NSArray *)arrOfModel
{
    if (arrOfModel.count != 0) {
        _arrOfModel = arrOfModel;
    }
    [_collectionView reloadData];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
